package Method;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Conexcute {
    public boolean execute(String sql){
        try {
            Connection con = null;
            Statement stmt = null;
            System.out.println("ccccccccccccccccc");
            Class.forName("org.h2.Driver");
            /*url后面加的?useUnicode=true&characterEncoding=gbk，是为了处理向数据库中添加数据时出现乱码的问题。*/
            String url = "jdbc:h2:~/test5";
            System.out.println("ccccccccccccccccc");
            con = DriverManager.getConnection(url, "sa", "sa");
            stmt = con.createStatement();
            System.out.println(sql);
            stmt.executeUpdate(sql);
            System.out.println("ccccccccccccccccc");
            stmt.close();
            con.close();
            return true;
        } catch (Exception e) {
           return false;
        }
    }
}
